package cn.pangza.user.mapper;

import cn.pangza.user.entity.po.Role;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface RoleMapper extends BaseMapper<Role> {

    @Select("select r.id, r.name, r.name_zh from role r, system_user_role ur where ur.role_id = r.id and ur.system_user_id = #{id} and r.delete_flag = 0")
    List<Role> selectRoleListByUserId(Integer id);

    @Delete("delete from system_user_role where system_user_id = #{userId}")
    void deleteUserRoleByUserId(Integer userId);

    @Select("select menu_id from menu_role where role_id=#{id}")
    List<Integer> getMenuIdSByRoleId(Integer id);

    @Delete("delete from menu_role where role_id=#{roleId}")
    void removeMenuByRoleId(@Param("roleId") Integer roleId);

    void saveRoleMenu(@Param("roleId") Integer roleId, @Param("menuIds") List<Integer> menuIds);

    @Delete("delete  from system_user_role where system_user_id=#{userId}")
    void removeRoleByUserId(@Param("userId") Integer userId);

    void updateUserRole(@Param("userId") Integer userId, @Param("roleIds") List<Integer> roleIds);

    @Select("select role_id from system_user_role where system_user_id=#{id}")
    List<Integer> getRoleIdsByUserId(Integer id);
}
